//
// Created by lingzhitech on 25-9-12.
//
// input transactions contain ISBN, number of copies sold, and sales price

#include <fstream>
#include <iostream>
#include "../material/Sales_data.h"


int main(int argc, char* argv[]) {
    std::ifstream input(argv[1]); // open the file of sales transactions
    std::ofstream output(argv[2]); // open the output file
    Sales_data total; // variable to hold the running sum
    if (read(input, total)) { // read the first transaction
        Sales_data trans; // variable to hold data for the next transaction
        while(read(input, trans)) { // read the remaining transactions
            if (total.isbn() == trans.isbn()) // check isbns
                total.combine(trans); // update the running total
            else {
                print(output, total); // print the results
                total = trans; // process the next book
            }
        }
        print(output, total); // print the last transaction
    } else // there was no input
        std::cerr << "No data?!" << std::endl;
}